﻿using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StockAna
{
    class Rate
    {
        public Rate()
        {
            defRate = 6;

            SQLiteDataReader reader = Config.ReadSql("SELECT rate FROM rates LIMIT 1;");
            if(reader.Read()){
                defRate = reader.GetDouble(0);
            }
        }

        public double defRate { get; set; }

        public double Discount(int year)
        {
            double yearRate = 1 + defRate / 100;
            return 1 / Math.Pow(yearRate, year);
        }

        public void Save()
        {
            Config.RunSql("DELETE * FROM rates;");
            Config.RunSql(string.Format("INSERT INTO rates VALUES(1, {0});", defRate));
        }
    }
}
